package com.cn.onetrip.adapter;

import java.util.ArrayList;

import com.cn.onetrip.activity.R;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MoreGridAdapter extends BaseAdapter {

	private ArrayList<String> mNameList = new ArrayList<String>();
	private ArrayList<Drawable> mDrawableList = new ArrayList<Drawable>();
	private LayoutInflater mInflater;
	private Context mContext;

	public MoreGridAdapter(Context context, ArrayList<String> nameList,
			ArrayList<Drawable> drawableList) {
		mNameList = nameList;
		mDrawableList = drawableList;
		mContext = context;
		mInflater = LayoutInflater.from(context);
	}

	public int getCount() {
		return mNameList.size();
	}

	public Object getItem(int position) {
		return mNameList.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ItemViewTag viewTag;

		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.grid_item_more, null);

			// construct an item tag
			viewTag = new ItemViewTag(
					(RelativeLayout) convertView.findViewById(R.id.grid_id),
					(ImageView) convertView.findViewById(R.id.grid_icon),
					(TextView) convertView.findViewById(R.id.grid_name));
			convertView.setTag(viewTag);
		} else {
			viewTag = (ItemViewTag) convertView.getTag();
		}

		// set name
		viewTag.mName.setText(mNameList.get(position));

		// set icon
		viewTag.mIcon.setBackgroundDrawable(mDrawableList.get(position));
		return convertView;
	}

	class ItemViewTag {
		protected RelativeLayout gridLayout;
		protected ImageView mIcon;
		protected TextView mName;

		/**
		 * The constructor to construct a navigation view tag
		 * 
		 * @param name
		 *            the name view of the item
		 * @param size
		 *            the size view of the item
		 * @param icon
		 *            the icon view of the item
		 */
		public ItemViewTag(RelativeLayout gridLayout, ImageView icon,
				TextView name) {
			this.gridLayout = gridLayout;
			this.mName = name;
			this.mIcon = icon;
		}
	}

}